#include "Read.h"

using namespace std;

Read::Read(vm *_env, int _ln)
    : env(_env), Stmt(_ln)
{
}


Read::~Read(void)
{
    for (auto iter = idList.begin(); iter != idList.end(); ++iter)
        delete *iter;
}

int Read::Eval()
{
    for (auto iter = idList.begin(); iter != idList.end(); ++iter)
    {
        if (env->HasNextData())
        {
            Assignable *id = *iter;
            if (id->Type() == INT)
            {
                int value = (int)env->GetNextFltData();
                id->SetValue(value);
            }
            else if (id->Type() == FLT)
            {
                float value = env->GetNextFltData();
                id->SetValue(value);
            }
        }
        else
        {
            return END_LINE;
        }        
    }    

    return -1;
}

void Read::AddVar( Assignable *var )
{
    idList.push_back(var);
}
